package businesCard;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import common.DateHelper;
import domain.BusinessCard;
import grasil.org.prototyp.R;
import grasil.org.prototyp.RowItem;

/**
 * Created by Peter on 10. 8. 2014.
 */
public class BusinessCardAdapter extends BaseAdapter {

    private List<BusinessCard> businessCards;
    private Context context;

    public BusinessCardAdapter(Context context, List<BusinessCard> businessCards) {
        this.context=context;
        this.businessCards = businessCards;
    }

    @Override
    public int getCount() {
        return businessCards.size();
    }

    @Override
    public Object getItem(int position) {
        return businessCards.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.business_card_list_item, null);
            viewHolder=new ViewHolder();
            viewHolder.name= (TextView) convertView.findViewById(R.id.textView);
            viewHolder.priority= (TextView)  convertView.findViewById(R.id.textView2);
            viewHolder.dateCreated= (TextView) convertView.findViewById(R.id.textView3);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.name.setText(businessCards.get(position).getName());
        viewHolder.priority.setText(String.valueOf(businessCards.get(position).getPriority()));
        viewHolder.dateCreated.setText(DateHelper.getDate(businessCards.get(position).getDateCreated()));
        return  convertView;
    }

    class ViewHolder{
        TextView name;
        TextView priority;
        TextView dateCreated;
    }
}
